if exists (select 1
            from  sysobjects
           where  id = object_id('bd_kq_approvalRecord')
            and   type = 'U')
   drop table bd_kq_approvalRecord
go

/*==============================================================*/
/* Table: bd_kq_approvalRecord                                  */
/*==============================================================*/
create table bd_kq_approvalRecord (
   id                   numeric              identity,
   order_id             int                  not null,
   process_id           varchar(64)          not null,
   approve_key          varchar(64)          not null,
   approve_order        int                  not null,
   node_name            varchar(64)          not null,
   handler_id           varchar(64)          not null,
   status               int                  not null default 0,
   create_time          datetime             not null default getdate(),
   remark               varchar(2000)        null,
   constraint PK_BD_KQ_APPROVALRECORD primary key (id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bd_kq_approvalRecord') and minor_id = 0)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '考勤管理--实例流程记录表',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'order_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'order_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '单子ID',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'order_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'process_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'process_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '流程实例ID',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'process_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approve_order')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'approve_order'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '流程步骤号',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'approve_order'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'node_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'node_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '流程节点名',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'node_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'handler_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'handler_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '处理人ID',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'handler_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '审批结果0:拒绝，1:通过',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_kq_approvalRecord')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '数据创建时间',
   'user', @CurrentUser, 'table', 'bd_kq_approvalRecord', 'column', 'create_time'
go
